# -*- coding: utf-8 -*-
# @Time    : 2021/3/17 9:56
# @Author  : wenyao
# @Email   : 343292019@qq.com
# @File    : 01.数字.py

########整型（int）
#python2有长整型（long）， python3 没有
#  python2  vs  python3
# [root@localhost ~]# python2
# Python 2.7.5 (default, Oct 30 2018, 23:45:53)
# [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
# Type "help", "copyright", "credits" or "license" for more information.
#     >>> a=78
# >>> type(a)
# <type 'int'>
# >>> a=999999999999999999999999999999999999999999999999999999999
# >>> type(a)
# <type 'long'>
#---------------------------------------------------------------------
# [root@localhost ~]# python3
# Python 3.6.8 (default, Nov 16 2020, 16:55:22)
# [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
# Type "help", "copyright", "credits" or "license" for more information.
#     >>> a=78
# >>> type(a)
# <class 'int'>
# >>> a=999999999999999999999999999999999999999999999999999999999
# >>> type(a)
# <class 'int'>

#######浮点型（float）
# >>> b=1.2
# >>> type(b)
# <class 'float'>

##########复数（complex）
# >>> c = 5+4.3j
# >>> type(c)
# <class 'complex'>

###########进制表示#############

######二进制#####
#以0b开头，只包含0，1两个数，缝2进1
# >>> a=0b11
# >>> a
# 3
# >>> type(a)
# <class 'int'>

#a=0b1010101
   # --- 1*2**6+0*2**5+1*2**4+...+1*2**0

#进制转换-bin:任意进制转2进制, 接收一个int, 返回一个str
# >>> a=10
# >>> bin(a)
# '0b1010'
# >>> b=bin(a)
# >>> type(b)
# <class 'str'>
# >>> a
# 10


######八进制数
#以0o开头，只包含0-7的数，缝8进1
# >>> b=0o10
# >>> b
# 8

#进制转换-oct: 任意进制转8进制, 接收一个int, 返回一个str
# >>> a=10
# >>> b=oct(a)
# >>> b
# '0o12'


#####十六进制数
#以0x开头，只包含0-F的数，缝16进1

# 进制转换-hex: 任意进制转16进制, 接收一个int, 返回一个str
# >>> a=20
# >>> hex(a)
# '0x14'
# >>>

# 进制转换-int: 任意进制转10进制, 接收一个int/str, 返回一个int
# >>> a="20"
# >>> b=int(a)
# >>> b
# 20
# >>> int("0b11",base=2)
# 3

#练习
# num1 = input("请输入数字a:")
# num2 = input("请输入数字b:")
#
# print("输出a+b的和：",int(num1)+int(num2))

# num1 = int(input("请输入任意10进制数:"))
# print("二进制转换为：",bin(num1))
# print("八进制转换为：",oct(num1))
# print("十六进制转换为：",hex(num1))

######
# float 在python中是不精确的
#精确的使用decimal类
# >>> from decimal import Decimal
# >>> mydec = Decimal.from_float(12.222)
# >>> mydec
# Decimal('12.2219999999999995310417943983338773250579833984375')
# >>> mydec = Decimal(12.222)
# >>> mydec
# Decimal('12.2219999999999995310417943983338773250579833984375')
# >>> mydec = Decimal("12.222")
# >>> mydec
# Decimal('12.222')

######复数
#a+bj
#实部和虚部都存储的是浮点型
# >>> a=4+5.3j
# >>> a.real
# 4.0
# >>> a.imag
# 5.3



